package com.example.myapplication.room;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

//  singleton   单列
@Database(entities = {Student.class},version = 1,exportSchema = false)
public abstract class StudentDatabase extends RoomDatabase {


    //  student_database.db
    private static StudentDatabase INSTANCE;
    public static synchronized StudentDatabase getDatabase(Context mContext){
        if (INSTANCE == null) {
            INSTANCE = Room.databaseBuilder(mContext.getApplicationContext(),StudentDatabase.class,"student_database")
//                    .allowMainThreadQueries()//   允许可以在  main  线程运行   慎用  谷歌不推荐   单元测试可以用
                    .build();
        }
        return INSTANCE;
    }

    //  对外暴露
    public abstract StudentDao getStudentDao();
}
